<extend name="Base/common"/>
<block name="style">
    <link href="__CSS__/login_common.css" rel="stylesheet">
    <link href="__CSS__/reset.css" rel="stylesheet" />
    <link href="__CSS__/font-awesome.min.css" rel="stylesheet" />
</block>
<block name="body">
    <div class="wrap login_wrap">
        <div class="content">
            <div class="login_box" style="margin-top:-270px;">
                <div class="login_form">
                    <div class="login_title">
                        注册
                    </div>
                    <form action="#" method="post">

                        <div class="form_text_ipt">
                            <input name="username" type="text" placeholder="用户名/字符串和数字">
                        </div>
                        <div class="ececk_warning"><span>用户名不能为空</span></div>
                        <div class="form_text_ipt">
                            <input name="password" type="password" placeholder="密码/长度在6位上">
                        </div>
                        <div class="ececk_warning"><span>密码不能为空</span></div>

                        <div class="form_text_ipt">
                            <input name="repassword" type="password" placeholder="重复密码">
                        </div>
                        <div class="ececk_warning"><span>密码不能为空</span></div>

                        <div class="form_text_ipt">
                            <input name="nickname" type="text" placeholder="姓名">
                        </div>
                        <div class="ececk_warning"><span>姓名不能为空</span></div>

                        <div class="form_text_ipt">
                            <input name="mobile" type="text" placeholder="手机号">
                        </div>
                        <div class="ececk_warning"><span>手机号不能为空</span></div>

                        <div class="form_text_ipt">
                            <select name="department" id="#department" style="border: none;height: 100%;width: 100%;">
                                <option value="">选择所属部门</option>
                                <volist name="department_info" id="vo">
                                    <option value="{$vo.id}">{$vo.title}</option>
                                </volist>
                            </select>
                        </div>
                        <div class="ececk_warning"><span>所属部门不能为空</span></div>

                        <div class="form_btn">
                            <button type="button" id="register_btn" onclick="javascript:;">注册</button>
                        </div>
                        <div class="form_reg_btn">
                            <span>有帐号？</span><a href="{:U('Index/login')}">直接登录</a>
                        </div>
                    </form>

                </div>
            </div>
        </div>
    </div>
</block>

<block name="script">
    <script type="text/javascript" src="__JS__/common.js" ></script>
    <script type="text/javascript">
        $(function(){
            $("#register_btn").click(function(){
                var submit = false;
                //表单验证
                $('.form_text_ipt input').each(function(){
                    if($(this).val()==""){
                        layer.msg("请填写完整信息！");
                        submit = false;
                        return false;
                    }else{
                        submit = true;
                    }
                });
                if(submit){
                    var $password=$("input[name=password]").val(),
                        $repassword=$("input[name=repassword]").val(),
                        $username=$("input[name=username]").val(),
                        $mobile=$("input[name=mobile]").val();

                    var u_re = /^[a-zA-z]\w{3,15}$/;

                    if(!u_re.test($username)){
                        layer.msg("用户名格式错误！");
                        return false;
                    }

                    if($password != $repassword){
                        layer.msg("密码和重复密码不一致！");
                        return false;
                    }


                    var m_re = /^1\d{10}$/
                    if (!m_re.test($mobile)) {
                        layer.msg("手机号格式错误！");
                        return false;
                    }

                    $.post('{:U("Index/register")}', $("form").serialize(), function(data){
                        if(data.status){
                            layer.msg(data.info)
                            setTimeout(function () {
                                location.href = data.url
                            },1000);
                        }else{
                            layer.msg(data.info);
                        }
                    });

                }

            })


        });
    </script>

</block>

